package com.wenson.creational.builder;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName: Building
 * @Author: luowangcheng
 * @Date: 2024/6/12 23:18
 * @Description: 建筑物基类
 */
public class Building {
    // 模拟建筑物组件的组装
    private List<String> buildingComponents = new ArrayList<>();

    // 地基
    public void setBasement(String basement) {
        this.buildingComponents.add(basement);
    }

    // 墙体
    public void setWall(String wall) {
        this.buildingComponents.add(wall);
    }

    // 屋顶
    public void setRoof(String roof) {
        this.buildingComponents.add(roof);
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        for (int i = buildingComponents.size() - 1; i >= 0; i--) {
            sb.append(buildingComponents.get(i));
        }
        return sb.toString();
    }
}
